package com.en.utils;

import com.en.config.GlobalConfig;
import com.microsoft.cognitiveservices.speech.SpeechConfig;
import com.microsoft.cognitiveservices.speech.SpeechSynthesizer;
import com.microsoft.cognitiveservices.speech.audio.AudioConfig;

/**
 * ClassName: tts
 * Package: com.en.utils
 * Description:
 *
 * @Date: 2024/1/16 11:08
 * @Author: wht
 */
public class tts {

    public static void englishToSpeech(String text) {
        SpeechConfig speechConfig = SpeechConfig.fromSubscription(GlobalConfig.speechKey, GlobalConfig.speechRegion);

        speechConfig.setSpeechSynthesisLanguage("en-US");
        speechConfig.setSpeechSynthesisVoiceName("en-US-JennyNeural");

        AudioConfig audioConfig = AudioConfig.fromWavFileOutput("/Users/wuhaitao/Desktop/" + text + ".mp3");

        SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(speechConfig, audioConfig);
        speechSynthesizer.SpeakText(text);
    }

    public static void chineseToSpeech(String text) {
        SpeechConfig speechConfig = SpeechConfig.fromSubscription(GlobalConfig.speechKey, GlobalConfig.speechRegion);

        speechConfig.setSpeechSynthesisLanguage("en-US");
        speechConfig.setSpeechSynthesisVoiceName("en-US-JennyNeural");

        AudioConfig audioConfig = AudioConfig.fromWavFileOutput("/Users/wuhaitao/Desktop/" + text + ".mp3");

        SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(speechConfig, audioConfig);
        speechSynthesizer.SpeakText(text);
    }
}
